package com.mkr.dao.impl;

import com.mkr.dao.UserDao;
import com.mkr.pojo.User;
import com.mkr.util.DBUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;


/**
 * @author mkr
 * @version V1.0
 * @Project BookApp
 * @Package com.mkr.dao.impl
 * @Description:
 * @Date 2022/5/13 22:34
 */
public class UserDaoImpl implements UserDao {
    //创建连接对象
    private QueryRunner runner = new QueryRunner(DBUtil.getDateSource());

    @Override
    public User findName(String uname) {
        //获取用户名、密码
        String sql = "select * from t_users where name = ? and password = ?";
        try {
            User user = runner.query(sql,new BeanHandler<>(User.class) ,uname);
            return user ;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }

}
